/**
 * Created by baiguiren on 1/16/17.
 */

let async = require('async');

let test_arr = [1, 2, 3, 4, 5];

async.every(test_arr, (item, callback) => {
  setTimeout(() => {
    callback(null, item > 2);
  }, Math.random() * 100);
}, (err, results) => {
  if (err) {
    console.log(err);
  } else {
    console.log(results);
  }
});

async.everyLimit(test_arr, 2, (item, callback) => {
  setTimeout(() => {
    console.log('finish1 ' + item);
    callback(null, item > 0);
  }, Math.random() * 100);
}, (err, results) => {
  console.log(err ? err : results);
});

async.everySeries(test_arr, (item, callback)=>{
  setTimeout(() => {
    console.log('finish2 ' + item);
    callback(null, item > 0);
  }, Math.random() * 100);
}, (err, results) => {
  console.log(err ? err : results);
});
